package com.itheima.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.common.R;
import com.itheima.dto.ModifyStatusDto;
import com.itheima.dto.OrdersPageDto;
import com.itheima.pojo.Orders;
import com.itheima.service.OrdersService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("order")
public class OrderController {

    @Resource
    private OrdersService ordersService;

    @GetMapping("page")
    public R getPage(OrdersPageDto dto) {

        Page<Orders> page = ordersService.getPage(dto);

        return R.success(page);
    }


    @PutMapping("")
    public R<String> modifyStatus(@RequestBody ModifyStatusDto dto) {

        if (dto.getStatus() != null && dto.getId() != null) {
            Boolean res = ordersService.modifyStatus(dto.getId(), dto.getStatus());

            return res ? R.success(null) : R.error(null);
        }

        return null;
    }

}

